<!DOCTYPE html>
<head>
  <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
  <title>Check Reverted CLs</title>
  <meta charset="utf-8">
  <link rel="stylesheet" href="/common.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script>
    function createUrl(parameters) {
      var params = [];
      for (var key in parameters) {
        if (parameters[key] != undefined) {
          params.push(key + '=' + parameters[key])
        }
      }

      if (params.length == 0) {
        return 'check-reverted-cls';
      } else {
        return 'check-reverted-cls?' + params.join('&');
      }
    };

    function processSuspectedCLsBetweenDateRange(e) {
      var parameters = {}
      parameters['start_date'] = $('#start_date').val() == 'mm/dd/yyyy' ? undefined : $('#start_date').val();
      parameters['end_date'] = $('#end_date').val() == 'mm/dd/yyyy' ? undefined : $('#end_date').val();
      newUrl = createUrl(parameters);
      window.location.replace(newUrl);
      e.preventDefault();
    };

    $(function() {
      $('#submit').click(processSuspectedCLsBetweenDateRange);
    });
  </script>
</head>
<body>
  <form>
    Start Date
    <input type="date" id="start_date" value={{ start_date }}></input>
    End Date
    <input type="date" id="end_date" value={{ end_date }}></input>
    <input type="submit" id="submit"></input>
  </form>
  <br>
  {% if processed %}
    <b>Findit created reverts for the following CLs</b><br>
    <table>
      <tr>
        <th></th>
        <th>Notification time</th>
        <th>Code review url</th>
        <th>Outcome</th>
      </tr>
      <tbody>
      {% for result in processed %}
        <tr>
          <td>{{ loop.index }}</td>
          <td>{{ result.cr_notification_time }}</td>
          <td><a href="{{ result.url }}" target="_blank">{{ result.url }}</a></td>
          <td>{{ result.outcome }}</td>
        </tr>
      {% endfor %}
      </tbody>
    </table>
  {% else %}
    No revert CLs were created in the date range specified that were verified
  {% endif %}
  <br>
  {% if undetermined %}
    <b>Findit could not determine the outcome of the following suspected CLs flagged for revert:</b><br>
    <table>
      <tr>
        <th></th>
        <th>Notification time</th>
        <th>Code review url</th>
      </tr>
      <tbody>
      {% for result in undetermined %}
        <tr>
          <td>{{ loop.index }}</td>
          <td>{{ result.cr_notification_time }}</td>
          <td><a href="{{ result.url }}" target="_blank">{{ result.url }}</a></td>
        </tr>
      {% endfor %}
      </tbody>
    </table>
  {% endif %}
</body>
